<!DOCTYPE html>
<html lang="zh_CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <!--公用头部-->
    <th:block th:replace="common/head::commonHead('邮箱新增-小邑')"/>
    <style>
        #formAdvForm .layui-row {
            margin-top: 20px;
        }

        #formAdvForm .layui-form-item {
            margin-bottom: 0;
        }

        #formAdvForm .layui-form-item .layui-inline {
            margin-bottom: 25px;
            margin-right: 0;
        }
        .layui-input-block{
            margin-left: 130px !important;
        }
        .layui-form-label{
            width: 100px !important;
        }
    </style>
</head>
<!--公用js-->
<th:block th:replace="common/head::commonJs"/>
<body marginwidth="0" marginheight="0">
<form class="layui-form" action="" id="formAdvForm" lay-filter="formAdvForm">
    <div class="layui-fluid  layui-fluid-btn">
        <div class="layui-col-md12">
            <div class="layui-card" style="margin: 10px;">
                <div class="layui-card-body">
                    <div class="layui-form-item layui-row">
                        <div class="layui-inline layui-col-md12">
                            <label class="layui-form-label layui-form-required">收件人邮箱</label>
                            <div class="layui-input-block">
                                <input type="text" name="receiver" id="receiver" lay-verify="required"
                                       placeholder="请输入收件人邮箱" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline layui-col-md12">
                            <label class="layui-form-label layui-form-required">邮件主体</label>
                            <div class="layui-input-block">
                                <input type="text" name="subject" id="subject" lay-verify="required"
                                       placeholder="请输入邮件主体" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline layui-col-md12">
                            <label class="layui-form-label layui-form-required">邮件正文</label>
                            <div class="layui-input-block">
                                <textarea type="text" name="content" id="content" lay-verify="required"
                                          placeholder="请输入邮件正文" autocomplete="off" class="layui-textarea"></textarea>
                            </div>
                        </div>
                    </div>
                    <div class="form-group-bottom">
                        <button class="xy-btn xy-btn-primary subCheckBtn" lay-submit lay-filter="formBtn">发送</button>
                        <button type="reset" class="xy-btn ">重置</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</form>
<script>
    layui.use(['layer', 'jquery', 'form', 'notice'], function () {
        var $ = layui.jquery
            , form = layui.form
            , notice = layui.notice
            , layer = layui.layer;

        //监听提交
        form.on('submit(formBtn)', function (data) {
            var loadIndex = null;
            checkSubBtn(1);
            sendAjaxPostToCallback(
                basePath + '/mail/addMail',
                data.field,
                function (result) {
                    if (result.success) {
                        // 提示信息
                        top.layui.notice.msg(result.msg, {icon: 1, position: "topCenter"});
                        // 获取当前iframe层的索引
                        var index = parent.layer.getFrameIndex(window.name);
                        // 关闭弹窗
                        parent.layer.close(index);
                        // 重载表格
                        parent.layui.table.reload('mailTable', {});
                    } else {
                        checkSubBtn(2);
                        top.layui.notice.msg(result.msg, {icon: 2, position: "topCenter"});
                    }
                },
                function (data) {
                    checkSubBtn(2);
                    if (utils.string.isEmpty(data) && utils.string.isEmpty(data.msg)) {
                        top.layui.notice.msg(data.msg, {icon: 2, position: "topCenter"});
                    } else {
                        top.layui.notice.msg("服务器内部错误，请联系管理员~", {icon: 2, position: "topCenter"});
                    }
                },
                function () {
                    loadIndex = layer.load(1);
                },
                function () {
                    layer.close(loadIndex);
                },
            )
            return false;
        });
    });
</script>
</body>
</html>
